<?php

use yii\helpers\Html;
use yii\grid\GridView;


$this->title = Yii::t('app', 'Suppliers');
$this->params['breadcrumbs'][] = $this->title;

?>
<div class="supplier-index">

    <div class="box">
        <div class="box-header">
          <?= Html::a(Yii::t('app', 'Create Supplier'), ['create'], ['class' => 'btn btn-success']) ?>
        </div>
        <div class="box-body">
        <p>
             <?php echo $this->render('_search', ['model' => $searchModel]); ?>
        </p>
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'layout'  =>  "{items}\n{summary}\n{pager}",
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],

                [
                        'attribute' => 'type',
                        'headerOptions' => ['width' => '10%'],
                        'filter' =>  Yii::$app->params['supplier_type'],
                        'value' => function ($model) {
                                return isset(Yii::$app->params['supplier_type'][$model->type])?Yii::$app->params['supplier_type'][$model->type]:'';
                            },
                ],

                [
                    'headerOptions' => ['width' => '15%'],
                    'attribute' => 'en_name',
                    'value' => function ($model) {
                            return $model->en_name;
                        },
                ],
           
                [
                    'headerOptions' => ['width' => '10%'],
                    'attribute' => 'person',
                    'value' => function ($model) {
                            return $model->person;
                        },
                ],
              
                [
                    'headerOptions' => ['width' => '10%'],
                    'attribute' => 'phone',
                    'value' => function ($model) {
                            return $model->phone;
                        },
                ],

                [
                    'attribute' => 'city',
                    'headerOptions' => ['width' => '15%'],
                    'value' => function ($model) {

                        return isset($model->cityName) ? $model->cityName->en_name.'—'.$model->cityName->zh_name : '';
                    },
                ],

                [
                    'headerOptions' => ['width' => '15%'],
                    'attribute' => 'email',
                    'format'=>'email',
                    'value' => function ($model) {
                            return $model->email;
                        },
                ],

                //'email:email',

                // [
                //      'attribute' => 'url',
                //      'format'=>'raw',
                //      'value' => function($model) { 
                //         return Html::a(Html::encode($model->url), Html::encode($model->url),['target'=>'_blank']);
                //      } 
                // ],
            
                [
                  'attribute' => 'user_id',
                  'headerOptions' => ['width' => '10%'],
                  'value' => function($model){

                        return isset($model->user) ? $model->user->name : '管理员';
                  }
                ],
                
                [
                    'class' => 'yii\grid\ActionColumn',
                    'headerOptions' => ['width' => '15%'],
                    'header' => '操 作',
                    'template' =>"{view} {update}"
                ],
            ],
        ]); ?>

        </div>
    </div>    
</div>
